package cn.nwpu.eckel.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.nwpu.eckel.model.MPS;
import cn.nwpu.eckel.model.User;

/**
 * Servlet implementation class NewMps
 */
@WebServlet("/NewMps")
public class NewMps extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public NewMps() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setContentType("text/html;charset=UTF-8");
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		
		int pNo=Integer.parseInt(request.getParameter("pNo"));
		String pName=request.getParameter("pName");
		String pType=request.getParameter("pType");
		
		HttpSession session=request.getSession();
		User user=(User)session.getAttribute("user");
		String planner=user.getName();
		
		int ph=Integer.parseInt(request.getParameter("ph"));
		int lt=Integer.parseInt(request.getParameter("lt"));
		int stock=Integer.parseInt(request.getParameter("stock"));
		int safeStock=Integer.parseInt(request.getParameter("safeStock"));
		int lotsize=Integer.parseInt(request.getParameter("lotsize"));
		int rf=Integer.parseInt(request.getParameter("rf"));
		int sf=Integer.parseInt(request.getParameter("sf"));
		MPS mps=new MPS(pNo,pName,pType,planner,ph,lt,stock,safeStock,lotsize,rf,sf);
		mps.create();
		response.sendRedirect("index.jsp");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
